#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.7.15 (beta)
 Author:         Ted Kent

 Script Function:
	A series of custom hotkeys for my personal use.

#ce ----------------------------------------------------------------------------
#RequireAdmin

HotKeySet("^!l", "logout")
HotKeySet("^!i", "login")

;loop to stay running and continue listening for hotkeys
While 1
	Sleep(1000)
WEnd


Func logout()
	Sleep(1000)
	BlockInput(1)
	Local $title

	getFirefox()
	MouseClick("left", 110, 15, 1, 0)
	Sleep(500)
	;right click the pinned gmail window and unpin it
	MouseClick("right", 110, 15, 1, 0)
	Sleep(500)
	Send("b")
	Sleep(500)
	;click the google account dropdown menu
	MouseClick("left", 1380, 107, 1, 0)
	Sleep(1000)
	;click signout
	MouseClick("left", 1290, 321, 1, 0)
	Sleep(1000)
	;close the window
	WinClose("[active]")
	BlockInput(0)
EndFunc

Func login()
	Sleep(1000)
	BlockInput(1)
	Local $title

	getFirefox()
	MouseClick("left", 113, 17, 1, 0)
	Sleep(500)
	MouseClick("left", 344, 43, 1, 0)
	Sleep(500)
	Send("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fhl%3Den%26tab%3Dwm%26ui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2&hl=en&from=login{ENTER}")
	Sleep(3000)
	$title = WinGetTitle("[active]")
	If StringInStr($title, "Gmail: Email from Google") Then
		MouseClick("left", 1156, 289, 1, 0)
		Send("Pyarone")
		MouseClick("left", 1167, 360, 1, 0)
		Send("hiragana2{ENTER}")
	EndIf
	MouseClick("right", 110, 15, 1, 0)
	Sleep(500)
	Send("p")
	Sleep(500)
	MouseClick("left", 110, 15, 1, 0)
	Sleep(500)
	Send("^t")
	Sleep(2000)
	Send("www.google.com{ENTER}")
	BlockInput(0)
EndFunc

Func verifyMaximized()
	Local $pos
	Local $size
	Local $x
	Local $y

	;position of maximize button relative to window:
	;X = xpos + xsize - 69
	;Y = ypos + 8
	;border size 8

	If WinGetState("[active]") < 32 Then
		$pos = WinGetPos("[active]")
		$size = WinGetClientSize("[active]")
		$x = $pos[0] + $size[0] + 16 - 69
		$y = $pos[1] + 8
		MouseClick("left", $x, $y, 1, 0)
		;MsgBox(1, "Window State", "X: " & $pos[0] & " + " & $size[0] & " + 16 - 69 = " & $x)
	EndIf
EndFunc

Func getFirefox()
	WinMinimizeAll()
	If WinExists("[CLASS:MozillaWindowClass]") Then
		MouseClick("left", 222, 876, 1, 0)
		Sleep(1000)
		verifyMaximized()
	Else
		Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
		WinWaitActive("[CLASS:MozillaWindowClass]")
		Sleep(1000)
		verifyMaximized()
	EndIf
	Sleep(4000)
EndFunc
